package com.example.swim.Config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author LiYa
 * @create 2022-11-06 17:15
 */
//因为前端是8081，后端是8080，不同端口，出现了跨域问题。
//    以下为解决跨域问题的配置代码
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
//                新版本的gateway 取消了allowedOrigins， 对应的变更为 allowedOriginPatterns
                .allowedOriginPatterns("*")
                .allowedMethods("GET","HEAD","POST","DELETE","OPTIONS","PUT")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
